<?php
header("Content-type: text/html; charset=utf-8");
require_once 'common.inc.php';
!in_array('2', $larr) && adminmsg('你没有被赋予操作该项的权限！');
$table=$tablepre.$ostable;
$order=" order by tdate desc ";
$typenames=array(
		'work'=>'党群工作',	
		'news'=>'综合信息',	
		'study'=>'学习天地',	
		'task'=>'任务指标',	
	);
if($ostable=='bume'){	
	$isEmpty=array(
		'buname'=>$buname,
	);
	$names="buname,types";
	$values="'$buname','$types'";
	$insert="insert into $table ($names) values ($values)";
	$update="buname='$buname',types='$types'";
	$order=" order by id desc ";
	$webtb='bume';	
}else if($ostable=='scrk'){
	$isEmpty=array(
		'title'=>$title,
		'tdate'=>$tdate,
	);
	$names="`title`,`tdate`,`yssr`,`fsjzx`,`ddjzx`,`hczxc`,`wdblk`,`dxc`,`dzc`,`fsd`";
	$values="'$title','$tdate','$yssr','$fsjzx','$ddjzx','$hczxc','$wdblk','$dxc','$dzc','$fsd'";
	$insert="insert into $table ($names) values ($values)";
	$update="title='$title',tdate='$tdate',yssr='$yssr',fsjzx='$fsjzx'
	,ddjzx='$ddjzx',hczxc='$hczxc',wdblk='$wdblk',dxc='$dxc'
	,dzc='$dzc',fsd='$fsd'";
	$webtb='scrk';	
}else{
	$isEmpty=array(
		'title'=>$title,
		'author'=>$author,
		'tdate'=>$tdate,
		'buid'=>$buid,
		'content'=>$content1,
		);
	$names="title,author,tdate,buid,content";
	$values="'$title','$author','$tdate','$buid','$content1'";
	$insert="insert into $table ($names) values ($values)";
	$update="title='$title',author='$author',tdate='$tdate',buid='$buid',content='$content1'";
	$webtb='web';
	$webtitle=$typenames[$ostable];
	$sql = "select id,buname from bl_bume where types='$ostable'";
	$query = $db-> query($sql);
	while ($resulte = $db-> fetch_array($query)) {
		$lists[] = $resulte;
		$nlist[$resulte['id']]=$resulte['buname'];
	} 
	//print_r($lists);die();
}
if ('list' == $action) {
	 $sql="SELECT COUNT(*) AS num FROM ".$table;
	$query = $db->query($sql);
	$totalnum = $db->result($query,0);
	$perpage = 13;
	$totalpages = ceil($totalnum/$perpage);
	if(!isset($page)||!is_numeric($page)){
		$page = 1;
	}
	$page = (int)$page;
	if($page>$totalpages||$page<1){
		$page = 1;
	}
	$start_limit = ($page-1)*$perpage;
	$pages=numofpage($totalnum,$page,$totalpages,"?action=$action&ostable=$ostable&");
	$checkdb = array();
	$sql = "select * from $table $order LIMIT $start_limit,$perpage";
	$query = $db-> query($sql);
	while ($resulte = $db-> fetch_array($query)) {
		$weblist[] = $resulte;
	}
	include_once MCC_ROOT . "/templates/msystem/{$webtb}list.htm";
} elseif ('edit' == $action) {
	//if(!checkValues(array('id'))){
		//adminmsg('参数错误11', "$PHP_SELF?ostable=$ostable&action=list");
	//}
	$action = 'oedit';
	$sql = "select * from $table where id='$id'";
	$query = $db-> query($sql);
	while ($resulte = $db-> fetch_array($query)) {
		$weblist = $resulte;
	} 
	include_once MCC_ROOT . "/templates/msystem/{$webtb}add.htm";
} elseif ('oedit' == $action) {
	//if(!checkValues(array('id'))){
		//adminmsg('参数错误', "$PHP_SELF?ostable=$ostable&action=list");
	//}
	$upsql=$update;
	if(!checkValues($isEmpty)){
		adminmsg('参数错误', "$PHP_SELF?ostable=$ostable&action=list");
	}
	//die();
	$sql = "update $table set $upsql where id='$id'";
	//die($sql);
	$query = $db-> query($sql);
	adminmsg('修改成功', "$PHP_SELF?ostable=$ostable&action=list");
} elseif ('delete' == $action) {
	if(!count($list)){
		adminmsg('参数错误', "$PHP_SELF?ostable=$ostable&action=list");
	}
	$del="'".implode("','",$list)."'";
	$sql = "delete from $table where id in($del)";
	$query = $db-> query($sql);
	adminmsg('删除成功', "$PHP_SELF?ostable=$ostable&action=list");
} elseif ('add' == $action) {
	$action = 'oadd';
	include_once MCC_ROOT . "/templates/msystem/{$webtb}add.htm";
} elseif ('oadd' == $action) {
	$sql = $insert;
	if(!checkValues($isEmpty)){
		adminmsg('参数错误', "$PHP_SELF?ostable=$ostable&action=list");
	}
	//die($sql);
	$query = $db-> query($sql);
	adminmsg('添加成功', "$PHP_SELF?ostable=$ostable&action=list");
}
?>